package lambda;

import entity.Employee;
import org.junit.Test;

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * Create with IDEA
 * author:yangyangkun
 * Date:2019/4/11
 * Time:9:47
 */
public class 构造器与数组引用 {
    //格式：  ClassName::new
    @Test
    public void test1(){
        Supplier<Employee> sup1 = () -> new Employee();
        Supplier<Employee> sup2 = Employee::new;  //调用无参构造器
        Employee emp = sup2.get();
        System.out.println(emp);
    }
    @Test
    public void test2(){
        Function<Integer,Employee> fun1 = (x) -> new Employee(x);
        Function<Integer,Employee> fun2 = Employee::new;
        Employee emp = fun2.apply(5);
        System.out.println(emp);

        //传两个参数
        BiFunction<Integer,Integer,Employee> fun3 = Employee::new;
        Employee emp2 = fun3.apply(45,5645);
        System.out.println(emp2);
    }
    //（2） 数组引用
    @Test
    public void test3(){
       Function<Integer,String[]> fu1 = (x) -> new String[x];
       Function<Integer,String[]> fu2 = String[]::new;
       String[] str = fu2.apply(3);
       System.out.println(str.length);
    }
}
